# -*- coding: utf-8 -*-
# @Time : 2023/11/29 15:07:24
# @Author : sacon
# @File : BaseFunction.py


import requests
from loguru import logger

def send(rule_str,start_content="# 全国图书馆联盟账号\n"):
    webhook_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=25c484f0-eb74-4344-8b1d-dcf92792d89c'

    data = {
        "msgtype": "markdown",  # 消息类型，此时固定为markdown
        "markdown": {
            "content": start_content+rule_str
        }}

    header = {'Content-Type': 'application/json'}
    try:
        respon = requests.post(webhook_url, headers=header, json=data)
        logger.info(f"Webhook推送结果通知 {respon.json()}")
    except Exception as e:
        logger.error(f"Webhook 推送结果失败通知 {e}")



def get_cookies(Type="sd", num=1):
    '''
    获取Cookies 列表
    :param Type:cnki,wanfang,cma,sd
    :param num:
    :return:
    '''
    url = f"http://cookie.dic.cool/get?num={num}&token=%qq123456..&name={Type}"
    response = requests.get(url, timeout=4)
    response_json = response.json()
    data = response_json["data"]
    if not data:
        logger.error(f"{Type}Cookies 为空！")
        return {}
    return data